#! /bin/bash
# setup the task to crontab
usage()
{
    echo "-------------"
    echo "usage:"
    echo "rmlog-setup.sh rmlogpath logdir"
    echo " rmlogpath    the rmlog.sh path(absolute)"
    echo " logdir       the log path"
    echo "-------------"
    exit 1
}

if [ $# -ne 2 ]; then
    echo "please specify the rmlogs.sh path"
    usage
fi

rmlogsh=$1

if [ ! -x "$rmlogsh" ]; then
    echo "the rmlog.sh can't excute"
    usage
fi

logdir=$2
hastask=$(cat /etc/crontab | grep rmlogs.sh)

#echo "has task :$hastask"

if [ -z "$hastask" ]; then
    echo "setup cront"
    echo "0 2 * * *  root ${rmlogsh} -n 2 -d ${logdir}" >> /etc/crontab
    #> /dev/null 2>&1
fi
